#include <stdio.h>
#include <unistd.h>
#define BUF_SIZE 30

int main() {
    int fd1[2], fd2[2];
    char str1[] = "who are you?";
    char str2[] = "thank you for your message";
    char buf[BUF_SIZE];
    
    pipe(fd1), pipe(fd2);
    pid_t pid = fork();
    if (pid == 0) {
        write(fd1[1], str1, sizeof(str1));
        read(fd2[0], buf, BUF_SIZE);
        printf("child proc output: %s \n", buf);
    } else {
        // 从0读出
        read(fd1[0], buf, BUF_SIZE);
        printf("Parent proc output: %s \n", buf);
        write(fd2[1], str2, sizeof(str2));
        // 防止子进程提前退出
        sleep(3);
    }
    return 0;
}